<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Running Examples</title>
</head>

<body>

<h2>Example-driven</h2>

<p>JBehave was developed as behaviour-driven and example-driven.  Read more about the 
<a href="examples-modules.html">examples modules</a> and 
<a href="examples-philosophy.html">examples philosophy</a>. 
</p>

<h2>Getting the source code</h2>

<p>Examples are not released as artifacts so the source code is needed to run them. 
The source code can be checked out from <a href="source-repository.html">source repository</a> 
or can be found as one of artifacts of the <b>jbehave-distribution</b> (the "src" zip bundle).
</p>

<h2>Running Examples with latest snapshot</h2>

<p>To build core modules and run examples with Maven:</p>
<script type="syntaxhighlighter" class="brush: plain"><![CDATA[
mvn -s settings.xml clean install -Pexamples
]]></script>

<span class="followup">The use of <b>settings.xml</b> is only required the first time you build  
(see <a href="building-source.html">building source</a>).
</span>

<p>The 'examples' profile instructs Maven to build the releasable modules and to verify their
behaviour by running the examples afterwards.</p>

<p>To run the GUI example too (requires non-headless mode):</p>
<script type="syntaxhighlighter" class="brush: plain"><![CDATA[
mvn clean install -Pexamples,gui
]]></script>

<span class="followup">If you are running the GUI example, see the note on <a href="building-source.html">building source</a>
for installing all the required dependendencies.
</span>

<h2>Running Examples against a fixed version</h2>

<p>In some cases, you may want to run the examples against a known version of JBehave.</p>

<script type="syntaxhighlighter" class="brush: plain">
<![CDATA[
cd examples
mvn clean install -Djbehave.version=[version]
]]>
</script>

<span class="followup">Note that running the examples in 'standalone' mode requires the JBehave parent POM to be present, as it
contains the information about the setup of the project, e.g. the compiler, the layout of the source, etc. </span>

<p>One option, is to pull the dependencies from the snapshots repository, activated by the <b>sonatype</b> profile in the <b>settings.xml</b>
provided next to the top-level POM.</p>

<script type="syntaxhighlighter" class="brush: plain">
<![CDATA[
cd examples 
mvn -Psonatype -s ../settings.xml clean install -Djbehave.version=[version]
]]>
</script>

<p>The other option is to install the parent POM from source:</p>

<script type="syntaxhighlighter" class="brush: plain">
<![CDATA[
mvn clean install -N <-- installs locally only JBehave parent POM (does not recurse into the child modules)
cd examples
mvn clean install -Djbehave.version=[version]
]]>
</script>

<span class="followup">As with any Maven artifact that is not expected to change, 
the build or retrieval is only required once, as it will be cached in the local repository. 
So, once you've built the JBehave parent POM from source or retrieved it from the snapshots
repository, you don't need to do it again, unless you think it needs to be updated.  The same goes for the 
Examples parent POM.</span>

<h2 id="ant">Running Examples via Ant</h2>

<p>The <b>trader-ant</b> example shows how to use JBehave Ant tasks to run stories.</p>

<p>Ant does not natively support any dependency management.  Ant users can either use 
<a href="http://maven.apache.org/ant-tasks">Maven Ant Tasks</a> or Apache Ivy or copy all the dependencies to a lib directory. 
In the trader-ant example we use the Maven Ant Tasks, which needs to be installed in the <b>$ANT_HOME/lib</b> directory 
in order to retrieve the dependency information from the Maven POM.</p>

<script type="syntaxhighlighter" class="brush: plain">
<![CDATA[
cd examples/trader-ant
ant -Djbehave.version=[version]
]]>
</script>

<div class="clear">
<hr />
</div>


</body>
</html>
